#include <iostream>
#include <vector>
#include <cstdlib>
#include <ctime>
#include <math.h>
#include <algorithm>
using namespace std;
void sort(vector<string>&str){
    int size=str.size();
    string temp;
    for(int i=0;i<size;i++){
        for(int j=i+1;j<size;j++){
            if(str[i].size()>str[j].size()){
                temp = str[j];
                str[j]=str[i];
                str[i]=temp;
            }
        }
    }
}

string longestCommonPrefix(vector<string>& strs) {
    short size=strs.size();
    string result="";
    sort(strs);
    for(short i=0;i<strs[0].size();i++){
        for(int j=1;j<size;j++){
            if(strs[j][i]!=strs[0][i]){
                return result;
            }
        }
        result+=strs[0][i];
    }
    return result;
}
int main(){

    vector<string>a;
    a.push_back("flower");
    a.push_back("flow");
    a.push_back("flight");

    vector<string>b;
    b.push_back("dog");
    b.push_back("racecar");
    b.push_back("car");

    vector<string>c;
    c.push_back("abca");
    c.push_back("abc");
    cout<<longestCommonPrefix(c)<<endl;
    return 0;
}